package site.teamo.biu.net.server.controller.model.client_management;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import site.teamo.biu.net.server.pojo.dto.ClientDTO;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * @author: 爱做梦的锤子
 * @date: 2023/3/26 16:00
 */
public class QueryClientListResponse extends LinkedList<QueryClientListResponse.ClientVO> {


    public QueryClientListResponse(List<ClientDTO> clientDTOS) {
        clientDTOS.stream()
                .map(ClientVO::from)
                .forEach(this::add);
    }

    @Data
    @Accessors(chain = true)
    public static class ClientVO {
        private String id;

        private String name;

        private String token;

        private boolean httpHttpsProxyServiceOnline;

        private Date createTime;

        private Date updateTime;

        public static ClientVO from(ClientDTO clientDTO) {
            ClientVO clientVO = new ClientVO();
            BeanUtil.copyProperties(clientDTO, clientVO);
            clientVO.setHttpHttpsProxyServiceOnline(clientDTO.getHttpHttpsProxyServiceOnline().booleanValue);
            String token = clientDTO.getToken();
            clientVO.setToken(StrUtil.hide(token, 4, token.length() - 4));
            return clientVO;
        }
    }
}
